<?php

ini_set("display_errors", "On");
error_reporting(E_ALL);

// 引入数据库连接文件
require_once '../../../sql/connection.php';

$bankID = $_POST['bankID'];
$addTitle = $_POST['addTitle'];
$addDes = $_POST['addDes'];
$addQType = $_POST['addQType'];
$addQType = (int)$addQType;

if ($addQType == 1){
	$addOpt1 = $_POST['addOpt1'];
	$addOpt2 = $_POST['addOpt2'];
	$addOpt3 = $_POST['addOpt3'];
	$addOpt4 = $_POST['addOpt4'];
	$addOptAnswer = $_POST['addOptAnswer'];
	$addComAnswer = "";
/*	echo $addOpt1 ;
	echo "\n";
	echo $addOpt2 ;
	echo "\n";
	echo $addOpt3 ;
	echo "\n";
	echo $addOpt4 ;
	echo "\n";
	echo $addOptAnswer;*/
}
else{
	$addOpt1 = "";
	$addOpt2 = "";
	$addOpt3 = "";
	$addOpt4 = "";
	$addOptAnswer = "";
	$addComAnswer = $_POST['addComAnswer'];
	// echo $addComAnswer ;
}

$now = date('Y-m-d H:i:s', time());
$addSql = "INSERT INTO question_info(create_time, update_time, bank_ID, question_title ,question_description , question_type,
                          question_opt_A,question_opt_B,question_opt_C, question_opt_D, question_opt_answer , question_completion_answer, is_delete)
			VALUES ('$now','$now','$bankID','$addTitle','$addDes','$addQType','$addOpt1','$addOpt2','$addOpt3','$addOpt4','$addOptAnswer','$addComAnswer',0)";

$bankTotalSql = "UPDATE bank_info set bank_total = bank_total + 1 where id = '$bankID'";

if (mysqli_query($GLOBALS['conn'], $addSql) && mysqli_query($GLOBALS['conn'], $bankTotalSql)) {
	echo "
            <script>
                alert('添加成功！');
                window.location.href=document.referrer;
            </script>
        ";
} else {
	echo "
            <script>
                alert('添加失败！');
                history.back();
            </script>
        ";
}
